import api from '../../http/apis/api';
export default {
    namespaced: true,
    state: {
        ruleForm: {
            salesPass: "",
            salesName: "",
            gender: "男",
            age: '',
            newsalesName: "",
            newsalesPassword: "",
        },
        power: 2,
        tableData: [],
        _id: "",
    },
    mutations: {
        //忘记密码·
        forgetPwd(state) {
            console.log('忘记密码');
        },
        //设置
        settableData(state, newData) {
            state.tableData = newData;
        },
        //设置_id
        set_id(state, info) {
            state.ruleForm.newsalesName = info.salesName;
            state.ruleForm.newsalesPassword = info.salesPassword;
            state.ruleForm.gender = info.gender;
            state.ruleForm.age = info.age;
            state._id = info._id
        },
        //重置
        reset(state) {
            state.ruleForm.salesName = "";
            state.ruleForm.salesPass = "";
            state.ruleForm.newsalesName = "";
            state.ruleForm.newsalesPassword = "";
            state.ruleForm.age = "";
        }

    },
    actions: {
        // 获取所有的销售人员(客户管理用)
         async getSales(){
            const { data } = await api.salesPerson.getSales();
          
            return data;
         },

        //获取销售人员
        async getSalesPerson(context) {
            const { data } = await api.salesPerson.getSalesPerson();
            context.commit('settableData', data.data)
        },
        //添加销售人员
        async addSalesPerson(context) {
            const { data } = await api.salesPerson.addSalesPerson({
                salesName: context.state.ruleForm.salesName,
                salesPassword: context.state.ruleForm.salesPass,
                age: context.state.ruleForm.age,
                gender: context.state.ruleForm.gender,
                img: "",
            });
            return data;
        },
        //删除
        async deleteSalesPerson(context, _id) {
            const { data } = await api.salesPerson.deleteSalesPerson(_id);
            return data;
        },
        //更改管理员信息
        async updataSalesPerson(context, state_radio) {
            const { data } = await api.salesPerson.updataSalesPerson({
                _id: context.state._id,
                adminName: context.state.ruleForm.newsalesName,
                password: context.state.ruleForm.newsalesPassword,
                age: context.state.ruleForm.age,
                gender: context.state.ruleForm.gender,
                state: state_radio
            });
            return data;
        },
        //获取xx销售的客户
        async getCustomer(context, _id) {
            const { data } = await api.salesPerson.getCustomer(_id);
            context.commit('settableData', data.data);
            return data;
        },
    }
}